package com.example.day2.busi.my;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.ToastUtils;
import com.example.day2.R;
import com.example.day2.adapter.StoreAdapter;
import com.example.day2.databinding.FragmentLiveBinding;
import com.example.day2.entity.VideoResult;
import com.example.day2.mvvm.base.BaseFragment;
import com.example.day2.mvvm.base.BaseViewFragment;


public class LiveFragment extends BaseFragment<FragmentLiveBinding,MyViewModel> {
    private StoreAdapter storeAdapter = new StoreAdapter(R.layout.item_store);

    @Override
    public void initView() {
        binding.rv.setLayoutManager(new GridLayoutManager(getContext(),2));
        binding.rv.setAdapter(storeAdapter);


    }

    @Override
    public void initData() {
        viewModel.getLives();
        viewModel.success.observe(this, new Observer<VideoResult>() {
            @Override
            public void onChanged(VideoResult videoResult) {
                if (videoResult.getCode() == 200){
                    storeAdapter.getData().addAll(videoResult.getData());
                    storeAdapter.notifyDataSetChanged();
                }else{
                    ToastUtils.showLong(videoResult.getMessage());
                }
            }
        });
    }

    @Override
    public Class<MyViewModel> getVIewModel() {
        return MyViewModel.class;
    }

    @Override
    public int bindLayoutId() {
        return R.layout.fragment_live;
    }
}